<template>
  <div class="login">
    <el-form :model="form" @submit.native.prevent="handleLogin">
      <el-form-item label="Username">
        <el-input v-model="form.username" required></el-input>
      </el-form-item>
      <el-form-item label="Password">
        <el-input type="password" v-model="form.password" required></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" native-type="submit">Login</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    handleLogin() {
      this.$store.dispatch('login', this.form).then(() => {
        this.$router.push('/')
      })
    }
  }
}
</script>

<style scoped>
.login {
  max-width: 400px;
  margin: 100px auto;
}
</style>
